package com.jeesite.modules.app.util.wx;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;

public class ServerIdleStateTrigger extends ChannelInboundHandlerAdapter {
	public static final String HEART_BEAT = "heart";
     @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    	System.out.println(HEART_BEAT);
    	 if(evt instanceof IdleStateEvent){
 			IdleState state=((IdleStateEvent)evt).state();
 			if(state == IdleState.WRITER_IDLE){
 				ctx.writeAndFlush(HEART_BEAT);
 			}else if(state == IdleState.READER_IDLE){
 				ctx.writeAndFlush(HEART_BEAT);
 			}else if(state == IdleState.ALL_IDLE){
 				ctx.writeAndFlush(HEART_BEAT);
 			}
 			
 		}else{
 			super.userEventTriggered(ctx, evt);
 		}
    }
}
